package com.xqgl.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xqgl.bean.Letter;
import com.xqgl.service.LetterDaoImp;

/**
 * Servlet implementation class addLetterServlet
 */
@WebServlet("/addLetterServlet")
public class addLetterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addLetterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;Charset=utf-8");
		String villagename = request.getParameter("villagename");
		String lettersource = request.getParameter("lettersource");
		String lettertitle = request.getParameter("lettertitle");
		String lettercontent = request.getParameter("lettercontent");
		String letterctime = request.getParameter("letterctime");
		String letterstate = request.getParameter("letterstate");
		
		Letter letter = new Letter();
		letter.setVillagename(villagename);
		letter.setLettersource(lettersource);
		letter.setLettertitle(lettertitle);
		letter.setLettercontent(lettercontent);
		letter.setLetterctime(letterctime);
		letter.setLetterstate(letterstate);
		
		LetterDaoImp imp = new LetterDaoImp();
		try {
			imp.add(letter);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect("letterlist.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
